//
//  CharacterCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 15/12/21.
//  Copyright © 2015年 game. All rights reserved.
//

#import "CharacterCell.h"
#import "ClassListModel.h"


@implementation CharacterCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
      

    }
    return self;
}

-(void)setClassAry:(NSArray *)classAry{

    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    for (int i = 0; i<classAry.count+1; i++) {
        UIButton *bnt = [UIButton buttonWithType:UIButtonTypeSystem];

        bnt.layer.borderColor = RGBA(220, 220, 220, 1).CGColor;
        if (i<classAry.count) {
             ClassListModel *model = classAry[i];
            [bnt setTitle:model.title forState:UIControlStateNormal];

        }else{
        
        [bnt setTitle:@"综合" forState:UIControlStateNormal];
        }
    
        [bnt setTintColor:RGBA(46,46,46,0.8)];
         bnt.backgroundColor = RGBA(245, 245, 245, 0.4);
        bnt.selected = NO;
        
        if (bnt.currentTitle.length<4) {
            bnt.titleLabel.font = font(SCREEN_WIDTH*0.05);
        }else{
            bnt.titleLabel.font = font(SCREEN_WIDTH*0.042);
        }
        
        bnt.tag = i+10;
        [bnt addTarget:self action:@selector(didSender:) forControlEvents:UIControlEventTouchUpInside];
        
        CGFloat xd = 10;//横间隙；
        CGFloat yd = 13;//竖间隙
        
        int row = i/4;
        int colum = i%4;
        
        CGFloat width;
        CGFloat hight = (220-yd*4)/3-10;
        
//        /*根据字体的个数给宽度*/
//        if (str.length<=4) {
            width = (SCREEN_WIDTH-xd*5)/4;
        
        CGFloat x = xd+(width + xd)*colum;
        CGFloat y = yd+(hight+yd)*row;
        
         bnt.frame = CGRectMake(x,y,width, hight);

        bnt.layer.borderWidth = 1;
       
        bnt.layer.masksToBounds = YES;
        radius(bnt,2);
        
        if ([bnt.currentTitle isEqualToString:self.title]) {
         
            [bnt setBackgroundImage:[UIImage imageNamed:@"icon-Select"] forState:UIControlStateNormal];
            bnt.layer.borderColor = [UIColor clearColor].CGColor;
            bnt.tintColor = mainColor;
        }

        [self.contentView addSubview:bnt];
        _cellHight = Height(bnt)+5;
    }
    
   }

#pragma mark---Click
/*
 用Block将button.tag值传递到Controller 实现button的跳转页面功能
 */
-(void)didSender:(UIButton *)sender{

    if (_ButtionBlock) {
        _ButtionBlock(sender);
    }
 
}

@end